<template>
  <section class="page">
    <headerbar>系统设置</headerbar>
    <section class="list-arrow mgt-2">
      <div class="item" @click="go('changeAvatar')">
        <span class="title">更换头像</span>
        <i class="arrow"></i>
      </div>
      <div class="item" @click="go('modifyPwd')">
        <span class="title">修改密码</span>
        <i class="arrow"></i>
      </div>
      <div class="item" @click="checkVersion()">
        <span class="title">更新版本</span>
        <i class="arrow"></i>
      </div>
      <!--<div class="item" @click="Privacy()">
        <span class="title">隐私政策</span>
        <i class="arrow"></i>
      </div>-->
<!--      <div class="item" @click="test()">
        <span class="title">测试</span>
        <i class="arrow"></i>
      </div>-->
      <div class="item" @click="clearDataDialog()">
        <span class="title">清除缓存</span>
        <i class="arrow"></i>
      </div>
      <div @click="logout" class="item">
        <span class="title">退出登录</span>
        <i class="arrow"></i>
      </div>
    </section>

    <p class="foot-version"><span class="color-tip">{{version}}</span></p>
  </section>
</template>

<script>
  import moment from 'moment'
  import tools from '@/utils/tools'
  import api from '@/common/config/api'
  import loginService from '@/service/loginService'
  import version from '@/common/version'
  import encrypt from '@/utils/encryptUtils'
  export default {
    name: 'setting',
    data () {
      return {
        fn: tools,
        version: version.versionName,
        data: {}
      }
    },
    created () {
      // this.loadData()
    },
    methods: {
      logout () {
        this.$localStorage.set('logoutFlag', '2')
        this.tools.loginOut()
      },
      loadData () {
        let data = {
          loginId: '3750',
          msgId: this.msgId
        }
        this.fetchService.nodeMsgDetail(data).then(res => {
          if (res.code !== 0) {
            return tools.tip(res.message)
          }
          this.data = res.data
        })
      },
      test () {
        this.$router.push({name: 'test'});
      },
      go (path) {
        this.$router.push({path: path})
      },
      checkVersion () {
        if (window.android && window.android.checkVersion) {
          window.android.checkVersion(version.version,encrypt.getUUID(6),tools.getToken(), 2)
        }
      },
      Privacy () {
        let url = "http://222.85.156.70:8888/privacy/Privacy.html";
        let title = "隐私政策";
        if (window.android && window.android.openUrlAdapt) {
          window.android.openUrlAdapt(url,title);
        }
      },
      clearDataDialog () {
        let _this = this
        this.$createDialog({
          type: 'confirm',
          icon: '',
          title: '温馨提示',
          content: '确认清除缓存？',
          confirmBtn: {
            text: '确定',
            active: true,
            disabled: false,
            href: 'javascript:;'
          },
          cancelBtn: {
            text: '取消',
            active: false,
            disabled: false,
            href: 'javascript:;'
          },
          onConfirm: () => {
            _this.clearData()
          },
          onCancel: () => {
          }
        }).show()
      },
      clearData () {
        if (window.android && window.android.clearCacheData) {
          window.android.clearCacheData()
          tools.tip('清除缓存成功！')
        }
      }
    }
  }
</script>

<style scoped lang="scss">
  .foot-version {
    position: fixed;
    bottom:10px;
    width:100%;
    text-align: center;
    font-size: 14PX;
  }
</style>
